/**
 * 拼装多纵坐标折线图
 * @param dataList
 * @param locationType
 * @param padding
 * @returns {*[]}
 * @author 赵京涛
 */
export const useLinesChartsData = (dataList, locationType, padding) => {
  const targetDataList = useTransformData(dataList)
  let maxAxisNum
  const data = []
  for (let i = 0; i < targetDataList.length; i++) {
    const position = (i % 2 === 0) ? 'left' : 'right'
    const index = Math.floor(i / 2)
    const currentOffset = position === 'left' ? index * locationType : index * locationType
    if (targetDataList[i].name === '水质类别') {
      maxAxisNum = 5
    } else if (targetDataList[i].name === '无机氮（mg/L）' || targetDataList[i].name === '无机氮(mg/L)' || targetDataList[i].name === '活性磷酸盐（mg/L）') {
      const maxValueObject = targetDataList[i].list
        .filter(item => item.value !== '')
        .reduce((maxObj, obj) => {
          const currentValue = parseFloat(obj.value)
          const currentMax = parseFloat(maxObj.value)
          return currentValue > currentMax ? obj : maxObj
        }, { name: '', value: '-Infinity' })
      let _targetMaxNum
      if (maxValueObject) {
        _targetMaxNum = (Number(maxValueObject.value) + 0.2).toFixed(1)
      } else {
        _targetMaxNum = null
      }
      maxAxisNum = _targetMaxNum
    } else if (targetDataList[i].name !== '无机氮（mg/L）' && targetDataList[i].name !== '无机氮(mg/L)' && targetDataList[i].name !== '活性磷酸盐（mg/L）') {
      const maxValueObject = targetDataList[i].list
        .filter(item => item.value !== '')
        .reduce((maxObj, obj) => {
          const currentValue = parseFloat(obj.value)
          const currentMax = parseFloat(maxObj.value)
          return currentValue > currentMax ? obj : maxObj
        }, { name: '', value: '-Infinity' })
      let _targetMaxNum
      if (maxValueObject) {
        _targetMaxNum = Number(maxValueObject.value)
      } else {
        _targetMaxNum = null
      }
      maxAxisNum = _targetMaxNum + 30
    } else {
      maxAxisNum = null
    }
    const obj = {
      nameLocation: 'middle',
      boundaryGap: [0, '50%'],
      max: maxAxisNum,
      splitNumber: targetDataList[i].name === '水质类别' ? 5 : 8, // 分割段数
      axisLine: {
        show: true,
        lineStyle: {
          color: '#000',
          width: 2
        }
      },
      // 调整名称的位置
      nameTextStyle: {
        padding: targetDataList[i].name === '细胞总密度（cells/L）' ? 68 : padding,
        color: '#000',
        fontFamily: 'Times New Roman, 黑体',
        fontSize: 16,
        fontWeight: 900
      },
      axisTick: {
        show: true,
        inside: 'false',
        length: 10
      },
      type: 'value',
      name: targetDataList[i].name,
      position: position,
      offset: currentOffset,
      axisLabel: {
        textStyle: {
          show: true,
          fontFamily: 'Times New Roman, 黑体',
          fontSize: 16,
          fontWeight: 900,
          color: '#000'
        },
        formatter: function(value) {
          if (targetDataList[i].name === '水质类别') {
            const target = {
              0: '无',
              1: 'Ⅰ类',
              2: 'Ⅱ类',
              3: 'Ⅲ类',
              4: 'Ⅳ类',
              5: '劣Ⅳ类'
            }
            return target[Math.round(value)]
          }
          return value
        },
        rich: {
          sup: {
            verticalAlign: 'super'
          }
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: '#ffffff',
          width: 1
        }
      }
    }
    data.push(obj)
  }
  return data
}

/**
 * 多折现图数据
 * @param dataList
 * @param isShow 头部是否显示单位
 * @param menuCode 统计类型ID
 * @param isShowRedTideBaseDensity 是否显示赤潮基准密度标准线
 * @returns {*[]}
 * @author 赵京涛
 */
export const useLinesSeriesData = (dataList, isShow, menuCode, isShowRedTideBaseDensity) => {
  const data = []
  let obj = {}
  for (let i = 0; i < dataList.length; i++) {
    if (dataList[i].name === '水质类别' || menuCode === '水质类别') {
      const listArr = dataList[i].list.map(k => k.value)
      const _menuObj = {
        '一类': 1,
        '二类': 2,
        '三类': 3,
        '四类': 4,
        '劣四类': 5,
        '': ''
      }
      const targetArr = listArr.map(target => _menuObj[target])
      obj = {
        name: dataList[i].name,
        type: 'line',
        connectNulls: true,
        data: targetArr,
        label: {
          show: isShow,
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体',
          position: 'top',
          formatter: function(params) {
            let category
            switch (params.value) {
              case 1:
                category = '一类'
                break
              case 2:
                category = '二类'
                break
              case 3:
                category = '三类'
                break
              case 4:
                category = '四类'
                break
              case 5:
                category = '劣四类'
                break
              default:
                category = ''
            }
            return category
          }
        },
        yAxisIndex: i,
        lineStyle: {
          type: 'solid',
          width: 4
        }
      }
    } else if (dataList[i].name === '浪级') {
      obj = {
        name: dataList[i].name,
        type: 'line',
        connectNulls: true,
        data: dataList[i].list.map(k => k.value),
        label: {
          show: isShow,
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体',
          position: 'top',
          formatter: function(params) {
            let category
            switch (params.value) {
              case '1':
                category = '微浪'
                break
              case '2':
                category = '小浪'
                break
              case '3':
                category = '轻浪'
                break
              case '4':
                category = '中浪'
                break
              case '5':
                category = '大浪'
                break
              case '6':
                category = '巨浪'
                break
              case '7':
                category = '狂浪'
                break
              case '8':
                category = '狂涛'
                break
              case '9':
                category = '怒涛'
                break
              default:
                category = ''
            }
            return category
          }
        },
        yAxisIndex: i,
        lineStyle: {
          type: 'solid',
          width: 4
        }
      }
    } else {
      obj = {
        name: dataList[i].name,
        type: dataList[i].name.includes('降雨量') ? 'bar' : 'line',
        connectNulls: true,
        data: dataList[i].list.map(k => k.value),
        yAxisIndex: i,
        barWidth: 10,
        itemStyle: {
          borderRadius: [10, 10, 0, 0],
          color: dataList[i].name.includes('降雨量') ? '#5C7BD9FF' : ''
        },
        label: {
          show: isShow,
          position: 'top',
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体'
        },
        lineStyle: {
          type: 'solid',
          width: 4
        },
        markLine: {
          silent: true,
          data: isShowRedTideBaseDensity && dataList[i]['jzmd'] && dataList[i]['jzmd'] !== '' ? [{ yAxis: dataList[i]['jzmd'], lineStyle: { color: dataList[i].color, name: dataList[i].name }}] : undefined,
          label: {
            show: true,
            position: 'end',
            offset: [-260, -10], // 设置偏移量，负值表示向左移动
            formatter: function(params) {
              return `${params.data.lineStyle.name.split('(')[0]}（赤潮基准密度×10⁴cell/L）`
            }
          }
        }
      }
    }
    data.push(obj)
  }
  return data
}

/**
 * 噪声实时数据
 * @param dataList
 * @param isShow
 * @param menuCode
 * @param isShowRedTideBaseDensity
 * @returns {*[]}
 */
export const useLinesRealTimeSeriesData = (dataList, isShow, menuCode, isShowRedTideBaseDensity) => {
  const data = []
  let obj = {}
  for (let i = 0; i < dataList.length; i++) {
    if (dataList[i].name === '水质类别' || menuCode === '水质类别') {
      const listArr = dataList[i].list.map(k => k.value)
      const _menuObj = {
        '一类': 1,
        '二类': 2,
        '三类': 3,
        '四类': 4,
        '劣四类': 5,
        '': ''
      }
      const targetArr = listArr.map(target => _menuObj[target])
      obj = {
        name: dataList[i].name,
        type: 'line',
        connectNulls: true,
        data: targetArr,
        label: {
          show: isShow,
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体',
          position: 'top',
          formatter: function(params) {
            let category
            switch (params.value) {
              case 1:
                category = '一类'
                break
              case 2:
                category = '二类'
                break
              case 3:
                category = '三类'
                break
              case 4:
                category = '四类'
                break
              case 5:
                category = '劣四类'
                break
              default:
                category = ''
            }
            return category
          }
        },
        yAxisIndex: i,
        lineStyle: {
          type: 'solid',
          width: 4
        }
      }
    } else if (dataList[i].name === '浪级') {
      obj = {
        name: dataList[i].name,
        type: 'line',
        connectNulls: true,
        data: dataList[i].list.map(k => k.value),
        label: {
          show: isShow,
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体',
          position: 'top',
          formatter: function(params) {
            let category
            switch (params.value) {
              case '1':
                category = '微浪'
                break
              case '2':
                category = '小浪'
                break
              case '3':
                category = '轻浪'
                break
              case '4':
                category = '中浪'
                break
              case '5':
                category = '大浪'
                break
              case '6':
                category = '巨浪'
                break
              case '7':
                category = '狂浪'
                break
              case '8':
                category = '狂涛'
                break
              case '9':
                category = '怒涛'
                break
              default:
                category = ''
            }
            return category
          }
        },
        yAxisIndex: i,
        lineStyle: {
          type: 'solid',
          width: 4
        }
      }
    } else {
      obj = {
        symbol: 'circle',
        symbolSize: 1,
        name: dataList[i].name,
        type: dataList[i].name.includes('降雨量') ? 'bar' : 'line',
        connectNulls: true,
        data: dataList[i].list.map(k => k.value),
        yAxisIndex: i,
        barWidth: 10,
        itemStyle: {
          borderRadius: [10, 10, 0, 0],
          color: dataList[i].name.includes('降雨量') ? '#5C7BD9FF' : ''
        },
        label: {
          show: isShow,
          position: 'top',
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体'
        },
        lineStyle: {
          type: 'solid',
          width: 4
        },
        markLine: {
          silent: true,
          data: isShowRedTideBaseDensity && dataList[i]['jzmd'] && dataList[i]['jzmd'] !== '' ? [{ yAxis: dataList[i]['jzmd'], lineStyle: { color: dataList[i].color, name: dataList[i].name }}] : undefined,
          label: {
            show: true,
            position: 'end',
            offset: [-260, -10], // 设置偏移量，负值表示向左移动
            formatter: function(params) {
              return `${params.data.lineStyle.name.split('(')[0]}（赤潮基准密度×10⁴cell/L）`
            }
          }
        }
      }
    }
    data.push(obj)
  }
  return data
}
/**
 * 多柱状图数据
 * @param dataList
 * @param isShow 头部是否显示单位
 * @param menuCode 统计类型ID
 * @param isShowRedTideBaseDensity 是否显示赤潮基准密度标准线
 * @param numberCodeType 统计类型code值
 * @returns {*[]}
 * @author 赵京涛
 */
export const useLinesSeriesDataBarCharts = (dataList, isShow, menuCode, isShowRedTideBaseDensity, numberCodeType) => {
  const lineChartsCodeArr = [201010104, 201060101, 201060103]
  const data = []
  let obj = {}
  for (let i = 0; i < dataList.length; i++) {
    if (dataList[i].name === '水质类别' || menuCode === '水质类别') {
      const listArr = dataList[i].list.map(k => k.value)
      const _menuObj = {
        '一类': 1,
        '二类': 2,
        '三类': 3,
        '四类': 4,
        '劣四类': 5,
        '': ''
      }
      const targetArr = listArr.map(target => _menuObj[target])
      obj = {
        name: dataList[i].name,
        type: lineChartsCodeArr.includes(Number(numberCodeType)) ? 'line' : 'bar',
        barWidth: 7,
        connectNulls: true,
        data: targetArr,
        label: {
          show: isShow,
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体',
          position: 'top',
          formatter: function(params) {
            let category
            switch (params.value) {
              case 1:
                category = '一类'
                break
              case 2:
                category = '二类'
                break
              case 3:
                category = '三类'
                break
              case 4:
                category = '四类'
                break
              case 5:
                category = '劣四类'
                break
              default:
                category = ''
            }
            return category
          }
        },
        yAxisIndex: i,
        lineStyle: {
          type: 'solid'
        },
        itemStyle: {
          color: dataList[i].name.includes('降雨量') ? '#5C7BD9FF' : '',
          barBorderRadius: [30, 30, 0, 0]
        }
      }
    } else {
      obj = {
        name: dataList[i].name,
        type: lineChartsCodeArr.includes(Number(numberCodeType)) && menuCode !== '秦皇岛站点降雨量(mm)' ? 'line' : 'bar',
        barWidth: 7,
        connectNulls: true,
        data: dataList[i].list.map(k => k.value),
        yAxisIndex: i,
        label: {
          show: isShow,
          position: 'top',
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体'
        },
        lineStyle: {
          type: 'solid'
        },
        itemStyle: {
          color: dataList[i].name.includes('降雨量') ? '#5C7BD9FF' : '',
          barBorderRadius: [30, 30, 0, 0]
        },
        markLine: {
          silent: true,
          data: isShowRedTideBaseDensity && dataList[i]['jzmd'] && dataList[i]['jzmd'] !== '' ? [{ yAxis: dataList[i]['jzmd'], lineStyle: { color: dataList[i].color, name: dataList[i].name }}] : undefined,
          label: {
            show: true,
            position: 'end',
            offset: [-260, -10], // 设置偏移量，负值表示向左移动
            formatter: function(params) {
              return `${params.data.lineStyle.name.split('(')[0]}（赤潮基准密度×10⁴cell/L）`
            }
          }
        }
      }
    }
    data.push(obj)
  }
  return data
}

/**
 * 单Y轴 | 区域单次评价图表Y轴结构
 * @param dataName
 */
export const regionOneTimeAppraiseYData = (dataName) => {
  return [
    {
      nameLocation: 'middle',
      boundaryGap: [0, '50%'],
      max: dataName === '水质类别' ? 5 : null,
      axisLine: {
        show: true
      },
      // 调整名称的位置
      nameTextStyle: {
        padding: 100,
        color: '#000',
        fontFamily: 'Times New Roman, 宋体',
        fontSize: 16,
        fontWeight: 900
      },
      axisTick: {
        show: true,
        inside: 'false',
        length: 10
      },
      type: 'value',
      name: dataName,
      position: 'left',
      offset: 0,
      axisLabel: {
        textStyle: {
          show: true,
          fontFamily: 'Times New Roman, 宋体',
          fontSize: 16,
          fontWeight: 900,
          color: '#000'
        },
        rich: {
          sup: {
            verticalAlign: 'super'
          }
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: '#ffffff',
          width: 1
        }
      }
    }
  ]
}

/**
 * 重组单纵坐标折线图数据
 * @param data
 * @param fileName
 * @returns {*|*[]}
 * @author 赵京涛
 */
export const drawChartsDataHandler = (data, fileName) => {
  return data.list.map(item => {
    const resItemList = item.list.map(listItem => {
      return {
        name: listItem.name,
        list: listItem.list.find(k => k.name === fileName)
      }
    })
    return {
      name: item.name,
      list: resItemList
    }
  })
}

/**
 * 重组单纵坐标折线图数据
 * @param data
 * @param fileName
 * @returns {*|*[]}
 * @author 赵京涛
 */
export const drawChartsDataCityHandler = (data, fileName) => {
  return data.list.map(item => {
    const resItemList = item.list[0].list.map(listItem => {
      return {
        name: listItem.name,
        list: {
          name: '降雨量（mm)',
          value: listItem.value
        }
      }
    })
    return {
      name: item.name,
      list: resItemList
    }
  })
}

/**
 * 按月组装数据
 * @param dataList 数据
 * @param typeName 污染物
 * @param resultShow 头部是否显示数值
 * @author 赵京涛
 */
export const currentSeriesDataMoonFun = (dataList, typeName, resultShow) => {
  const _menuObj = {
    '一类': 1,
    '二类': 2,
    '三类': 3,
    '四类': 4,
    '劣四类': 5,
    '': ''
  }
  if (Array.isArray(dataList) && dataList.length > 0) {
    if (typeName === '水质类别') {
      return dataList.map(item => {
        return {
          name: item.name,
          type: item.list[0].list.name === '秦皇岛站点降雨量(mm)' ? 'bar' : 'line',
          connectNulls: true,
          label: {
            show: resultShow,
            fontSize: 16,
            position: 'top',
            fontFamily: 'Times New Roman, 宋体',
            formatter: function(params) {
              let category
              switch (params.value) {
                case 1:
                  category = '一类'
                  break
                case 2:
                  category = '二类'
                  break
                case 3:
                  category = '三类'
                  break
                case 4:
                  category = '四类'
                  break
                case 5:
                  category = '劣四类'
                  break
                default:
                  category = ''
              }
              return category
            }
          },
          data: item.list.map(k => k.list.value).map(target => _menuObj[target])
        }
      })
    } else if (typeName === '浪级') {
      return dataList.map(item => {
        return {
          name: item.name,
          type: item.list[0].list.name === '秦皇岛站点降雨量(mm)' ? 'bar' : 'line',
          connectNulls: true,
          label: {
            show: resultShow,
            fontSize: 16,
            position: 'top',
            fontFamily: 'Times New Roman, 宋体',
            formatter: function(params) {
              let category
              switch (params.value) {
                case '1':
                  category = '微浪'
                  break
                case '2':
                  category = '小浪'
                  break
                case '3':
                  category = '轻浪'
                  break
                case '4':
                  category = '中浪'
                  break
                case '5':
                  category = '大浪'
                  break
                case '6':
                  category = '巨浪'
                  break
                case '7':
                  category = '狂浪'
                  break
                case '8':
                  category = '狂涛'
                  break
                case '9':
                  category = '怒涛'
                  break
                default:
                  category = ''
              }
              return category
            }
          },
          data: item.list.map(k => k.list.value)
        }
      })
    } else {
      return dataList.map(item => {
        return {
          name: item.name,
          type: item.list[0].list.name === '秦皇岛站点降雨量(mm)' ? 'bar' : 'line',
          barWidth: 10,
          connectNulls: true,
          itemStyle: {
            borderRadius: [10, 10, 0, 0]
          },
          label: {
            show: resultShow,
            fontSize: 16,
            fontFamily: 'Times New Roman, 宋体',
            position: 'top'
          },
          data: item.list.map(k => k.list.value)
        }
      })
    }
  }
}

/**
 * 按月组装数据 - 降雨量
 * @param dataList 数据
 * @param typeName 污染物
 * @param resultShow 头部是否显示数值
 * @author 赵京涛
 */
export const currentSeriesDataMoonCityFun = (dataList, typeName, resultShow) => {
  const _menuObj = {
    '一类': 1,
    '二类': 2,
    '三类': 3,
    '四类': 4,
    '劣四类': 5,
    '': ''
  }
  if (Array.isArray(dataList) && dataList.length > 0) {
    if (typeName === '水质类别') {
      return dataList.map(item => {
        return {
          name: item.name,
          type: 'bar',
          barWidth: 10,
          connectNulls: true,
          itemStyle: {
            borderRadius: [10, 10, 0, 0]
          },
          label: {
            show: resultShow,
            fontSize: 16,
            position: 'top',
            fontFamily: 'Times New Roman, 宋体',
            formatter: function(params) {
              let category
              switch (params.value) {
                case 1:
                  category = '一类'
                  break
                case 2:
                  category = '二类'
                  break
                case 3:
                  category = '三类'
                  break
                case 4:
                  category = '四类'
                  break
                case 5:
                  category = '劣四类'
                  break
                default:
                  category = ''
              }
              return category
            }
          },
          data: item.list.map(k => k.list.value).map(target => _menuObj[target])
        }
      })
    } else {
      return dataList.map(item => {
        return {
          name: item.name,
          type: 'bar',
          connectNulls: true,
          barWidth: 9,
          label: {
            show: resultShow,
            fontSize: 16,
            fontFamily: 'Times New Roman, 宋体',
            position: 'top'
          },
          data: item.list.map(k => k.list.value),
          itemStyle: {
            borderRadius: [10, 10, 0, 0]
          }
        }
      })
    }
  }
}

/**
 * 多柱状图数据重组
 * @param xData
 * @param dataList
 * @param fileName
 * @param isShow 头部是否显示单位
 * @author 赵京涛
 */
export const currentBarSeriesDataMoonFun = (xData, dataList, fileName, isShow) => {
  const _menuObj = {
    '一类': 1,
    '二类': 2,
    '三类': 3,
    '四类': 4,
    '劣四类': 5,
    '': ''
  }
  if (fileName !== '水质类别') {
    return xData.map((item, index) => {
      return {
        name: item,
        type: 'bar',
        connectNulls: true,
        data: extractData(item, dataList, fileName),
        barWidth: 7,
        label: {
          show: isShow,
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体',
          position: 'top'
        },
        itemStyle: {
          color: index === 0 ? '#3ecccc' : index === 1 ? '#9044da' : '#e14585',
          barBorderRadius: [30, 30, 0, 0]
        }
      }
    })
  } else if (fileName === '浪级') {
    return xData.map((item, index) => {
      return {
        name: item,
        type: 'bar',
        connectNulls: true,
        data: extractData(item, dataList, fileName),
        barWidth: 7,
        label: {
          show: isShow,
          fontSize: 16,
          position: 'top',
          fontFamily: 'Times New Roman, 宋体',
          itemStyle: {
            color: index === 0 ? '#3ecccc' : index === 1 ? '#9044da' : '#e14585',
            barBorderRadius: [30, 30, 0, 0]
          },
          formatter: function(params) {
            let category
            switch (params.value) {
              case '1':
                category = '微浪'
                break
              case '2':
                category = '小浪'
                break
              case '3':
                category = '轻浪'
                break
              case '4':
                category = '中浪'
                break
              case '5':
                category = '大浪'
                break
              case '6':
                category = '巨浪'
                break
              case '7':
                category = '狂浪'
                break
              case '8':
                category = '狂涛'
                break
              case '9':
                category = '怒涛'
                break
              default:
                category = ''
            }
            return category
          }
        }
      }
    })
  } else {
    return xData.map((item, index) => {
      return {
        name: item,
        type: 'bar',
        connectNulls: true,
        data: extractData(item, dataList, fileName).map(target => _menuObj[target]),
        barWidth: 7,
        label: {
          show: isShow,
          fontSize: 16,
          position: 'top',
          fontFamily: 'Times New Roman, 宋体',
          formatter: function(params) {
            let category
            switch (params.value) {
              case 1:
                category = '一类'
                break
              case 2:
                category = '二类'
                break
              case 3:
                category = '三类'
                break
              case 4:
                category = '四类'
                break
              case 5:
                category = '劣四类'
                break
              default:
                category = ''
            }
            return category
          }
        },
        itemStyle: {
          color: index === 0 ? '#3ecccc' : index === 1 ? '#9044da' : '#e14585',
          barBorderRadius: [30, 30, 0, 0]
        }
      }
    })
  }
}

/**
 * 多柱状图数据重组
 * @param xData
 * @param dataList
 * @param fileName
 * @param isShow 头部是否显示单位
 * @author 赵京涛
 */
export const currentBarSeriesDataMoonCityFun = (xData, dataList, fileName, isShow) => {
  const _menuObj = {
    '一类': 1,
    '二类': 2,
    '三类': 3,
    '四类': 4,
    '劣四类': 5,
    '': ''
  }
  if (fileName !== '水质类别') {
    return xData.map((item, index) => {
      return {
        name: item,
        type: 'bar',
        connectNulls: true,
        data: extractDataCity(item, dataList, fileName),
        barWidth: 7,
        label: {
          show: isShow,
          fontSize: 16,
          fontFamily: 'Times New Roman, 宋体',
          position: 'top'
        },
        itemStyle: {
          color: index === 0 ? '#3ecccc' : index === 1 ? '#9044da' : '#e14585',
          barBorderRadius: [30, 30, 0, 0]
        }
      }
    })
  } else {
    return xData.map((item, index) => {
      return {
        name: item,
        type: 'bar',
        connectNulls: true,
        data: extractData(item, dataList, fileName).map(target => _menuObj[target]),
        barWidth: 7,
        label: {
          show: isShow,
          fontSize: 16,
          position: 'top',
          fontFamily: 'Times New Roman, 宋体',
          formatter: function(params) {
            let category
            switch (params.value) {
              case 1:
                category = '一类'
                break
              case 2:
                category = '二类'
                break
              case 3:
                category = '三类'
                break
              case 4:
                category = '四类'
                break
              case 5:
                category = '劣四类'
                break
              default:
                category = ''
            }
            return category
          }
        },
        itemStyle: {
          color: index === 0 ? '#3ecccc' : index === 1 ? '#9044da' : '#e14585',
          barBorderRadius: [30, 30, 0, 0]
        }
      }
    })
  }
}
/**
 * @param keys
 * @param data
 * @param targetName
 * @returns {*[]}
 * @author 赵京涛
 */
const extractData = (keys, data, targetName) => {
  const result = []
  data.forEach(item => {
    const foundItem = findItemByName(item, targetName)
    if (foundItem) {
      const value = foundItem.list.find(subItem => subItem.name === keys).value
      result.push(value)
    }
  })
  return result
}

/**
 * @param keys
 * @param data
 * @param targetName
 * @returns {*[]}
 * @author 赵京涛
 */
const extractDataCity = (keys, data, targetName) => {
  const result = []
  data.forEach(item => {
    const info = item.list.find(s => s.name === keys)
    result.push(info)
  })
  return result.map(s => s.value)
}
/**
 * 递归查询
 * @param data
 * @param name
 * @returns {*|null}
 * @author 赵京涛
 */
const findItemByName = (data, name) => {
  if (data.name === name) {
    return data
  } else if (data.list) {
    for (let i = 0; i < data.list.length; i++) {
      // 递归查找
      const foundItem = findItemByName(data.list[i], name)
      if (foundItem) {
        return foundItem
      }
    }
  }
  return null
}
